package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.cgRecord;
import com.ruoyi.system.service.IcgRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 充电枪记录Controller
 * 
 * @author ruoyi
 * @date 2025-06-30
 */
@RestController
@RequestMapping("/system/cgrecord")
public class cgRecordController extends BaseController
{
    @Autowired
    private IcgRecordService cgRecordService;

    /**
     * 查询充电枪记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:cgrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(cgRecord cgRecord)
    {
        startPage();
        List<cgRecord> list = cgRecordService.selectcgRecordList(cgRecord);
        return getDataTable(list);
    }

    /**
     * 导出充电枪记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:cgrecord:export')")
    @Log(title = "充电枪记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, cgRecord cgRecord)
    {
        List<cgRecord> list = cgRecordService.selectcgRecordList(cgRecord);
        ExcelUtil<cgRecord> util = new ExcelUtil<cgRecord>(cgRecord.class);
        util.exportExcel(response, list, "充电枪记录数据");
    }

    /**
     * 获取充电枪记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cgrecord:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Integer recordId)
    {
        return success(cgRecordService.selectcgRecordByRecordId(recordId));
    }

    /**
     * 新增充电枪记录
     */
    @PreAuthorize("@ss.hasPermi('system:cgrecord:add')")
    @Log(title = "充电枪记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody cgRecord cgRecord)
    {
        return toAjax(cgRecordService.insertcgRecord(cgRecord));
    }

    /**
     * 修改充电枪记录
     */
    @PreAuthorize("@ss.hasPermi('system:cgrecord:edit')")
    @Log(title = "充电枪记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody cgRecord cgRecord)
    {
        return toAjax(cgRecordService.updatecgRecord(cgRecord));
    }

    /**
     * 删除充电枪记录
     */
    @PreAuthorize("@ss.hasPermi('system:cgrecord:remove')")
    @Log(title = "充电枪记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Integer[] recordIds)
    {
        return toAjax(cgRecordService.deletecgRecordByRecordIds(recordIds));
    }

    // 查询所有充电站下拉
    @GetMapping("/stationList")
    public AjaxResult stationList() {
        return AjaxResult.success(cgRecordService.selectAllStationSimple());
    }

    // // 充电枪分析总览
    // @GetMapping("/gunAnalysis")
    // public AjaxResult gunAnalysis(@RequestParam Integer stationId) {
    //     return AjaxResult.success(cgRecordService.selectGunAnalysisByStationId(stationId));
    // }

    // // 充电枪分析-按天统计
    // @GetMapping("/gunAnalysisDaily")
    // public AjaxResult gunAnalysisDaily(@RequestParam Integer stationId) {
    //     return AjaxResult.success(cgRecordService.selectDailyGunAnalysis(stationId));
    // }

    // 充电枪分析总览-按月
@GetMapping("/gunAnalysis")
public AjaxResult gunAnalysis(@RequestParam Integer stationId, @RequestParam String month) {
    return AjaxResult.success(cgRecordService.selectGunAnalysisByStationIdAndMonth(stationId, month));
}

// 充电枪分析-按天统计-按月
@GetMapping("/gunAnalysisDaily")
public AjaxResult gunAnalysisDaily(@RequestParam Integer stationId, @RequestParam String month) {
    return AjaxResult.success(cgRecordService.selectDailyGunAnalysisByMonth(stationId, month));
}
}
